package com.sfy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sfy.mapper.EmpMapper;
import com.sfy.pojo.Emp;
import com.sfy.pojo.PageBean;
import com.sfy.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empmapper;

//    //分页查询
//    @Override
//    public PageBean selectByPage(Integer page, Integer pageSize) {
//
//        Integer start = (page - 1) * pageSize;
//        List<Emp> rows = empmapper.selectByPage(start,pageSize);
//
//        Long total = empmapper.count();
//
//        PageBean pageBean = new PageBean(total,rows);
//
//        return pageBean;
//    }
//分页查询
@Override
    public PageBean selectByPage(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDateTime end) {


    PageHelper.startPage(page,pageSize);//页码，每页数量

    //条件查询
    List<Emp> empList = empmapper.selectByPage(name,gender,begin,end);
    //转为Page类型
    Page p = (Page) empList;
    long total = p.getTotal();
    List list = p.getResult();

    PageBean pageBean = new PageBean(total, list);

    return pageBean;
    }
}
